﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using org.sablecc.grammars.java_1_5.analysis;
using org.sablecc.grammars.java_1_5.node;

namespace Commander.Parsing.Visitors {
  public class MethodVisitor : DepthFirstAdapter {
    MethodInformation info = new MethodInformation();
    public MethodInformation Info { get { return info; } }

    public override void CaseAMethodDeclarator(org.sablecc.grammars.java_1_5.node.AMethodDeclarator node) {
      info.MethodName = node.GetIdentifier().Text;
     // info.Parameters.FormalParameter = node.GetFormalParameterList();
      base.CaseAMethodDeclarator(node);
    }

		public override void CaseAPrimitiveFormalParameter(APrimitiveFormalParameter node) {
			if (!(node.Parent() is ACatchClause))
				info.Parameters.Add(node);
			base.CaseAPrimitiveFormalParameter(node);
		}

		public override void CaseAReferenceFormalParameter(AReferenceFormalParameter node) {
			if(!(node.Parent() is ACatchClause))
				info.Parameters.Add(node);
			base.CaseAReferenceFormalParameter(node);
		}

    public override void CaseAMarkerAnnotation(AMarkerAnnotation node) {
      info.Annotation = node;
      base.CaseAMarkerAnnotation(node);
    }
    public override void CaseAMethodDeclaration(org.sablecc.grammars.java_1_5.node.AMethodDeclaration node) {
      info.Body = node.GetMethodBody();
			info.FullMethod = node.ToString();
      base.CaseAMethodDeclaration(node);
    }

    public override void CaseAPrimitiveMethodHeader(APrimitiveMethodHeader node) {
      info.Modifiers = (TypedList) node.GetModifiers();
      base.CaseAPrimitiveMethodHeader(node);
    }

    public override void CaseAReferenceMethodHeader(AReferenceMethodHeader node) {
      info.Modifiers = (TypedList)node.GetModifiers();
      base.CaseAReferenceMethodHeader(node);
    }

    public override void CaseASimpleMethodInvocation(ASimpleMethodInvocation node) {
      info.Invocations.Add(node);
      base.CaseASimpleMethodInvocation(node);
    }

    public override void CaseALocalVariableDeclarationStatement(org.sablecc.grammars.java_1_5.node.ALocalVariableDeclarationStatement node) {
      info.LocalVariables.Add(node.GetLocalVariableDeclaration());
      base.CaseALocalVariableDeclarationStatement(node);
    }
  }
}
